function [para, dat] = brukerin(fileb)
% function to read in bruker data files
global TITLE

% name='af66701.dta'; %Enter file that you would like to simulate.
name = fileb;
%mode='dat';
mode='dta';
switch mode
  case 'dat'
    data=load(name','-ascii');
    f=data(:,1);
    a=data(:,2);
    c=zeroLine(a,0.05);
  case 'dta'
    [f, c, p] = eprload(name);
    
end
c = real(c);
dat = c;
% axes(handles.dataPlot);
% plot(f,c)

isim = 1;
% Find number of points
NSTEP = p.XPTS;
para(13) = NSTEP;
% Find "initial value" for field swept, this is low-field but for pulsed
% experiments, it's likely to be zero
XMIN = p.XMIN;
% Find data width, gauss or nsec
XWID = p.XWID;
% At this point we don't know what type of experiment this is so store
% values in places for time domain or field swept
para(27) = XWID;
para(10) = XMIN + 0.5*XWID;
deltau = (XWID)/real(NSTEP - 1);
para(21) = deltau;
% Get title line
TITLE = p.TITL;
% Read in center field then convert T to G
A1CT = p.A1CT;
para(10) = 1.0E4*A1CT;
% Microwave frequency
FREQ = p.MWFQ;
para(9) = FREQ/1.0E9;
% sample temp (STMP) cannot be found
% Read number of scans
avg = p.AveragesPerScan;
para(15) = avg;
idel1 = sscanf(p.FTEzDelay1, '%f');
idel2 = sscanf(p.FTEzDelay2, '%f');
idelx = sscanf(p.FTEzDeltaX, '%f');
gate = sscanf(p.FTEzIntgGate, '%f');
iPW90 = sscanf(p.FTEzMWPiHalf, '%f');
SRT = sscanf(p.ShotRepTime, '%f');

% Until we define standard pulspel names, have user input of experiment
% type
% isim = 21 means called from rapid
% isim = 22 means called from tmdynam
if isim ~= 21 || isim ~= 22
  choices = {'2-pulse field-swept echo decay'; '2-pulse spin echo';...
    '3-pulse spin echo'; 'inversion recovery'; 'picket-fence inv. recovery';...
    'saturation recovery'; 'for other Elexsys exp.'};
  [iexp, ok] = listdlg('PromptString','Select experiment type:',...
    'SelectionMode','single','ListString',choices);
end
if ok == 0
  return
end

% Just working with the reals for now
% if icpl == 1
%   disp('read the imaginary channel');
% end
if isim == 21
  iexp = 7;
end
if isim == 22
  iexp = 2;
end
para(8) = iexp;
if iexp == 5 || iexp == 6
  para(8) = 4;
end
% what we do with delays and pulses depends on experiment
if iexp == 1 || iexp == 2
  para(20) = idel1;               % initial time
  para(21) = idelx;               % delta tau
  para(18) = iPW90;               % pw1
  para(19) = 2*iPW90;             % pw2
end
if iexp == 4
  para(20) = idel2 + 2*idel1;     % initial time
  para(18) = 2*iPW90;             % pw1
  para(19) = iPW90;               % pw2
  para(22) = 2*iPW90;             % pw3
end
% now put in some default values
% field controller is Bruker
para(32) = 2;
% phase alternation is on
para(7) = 2;
% number of averages must be at least 1
if para(15) == 0.0
    para(15) = 1;
end
% default as 1 kW TWT
para(24) = 1;
% if have not found initial time, enter manually, except for field swept
if isim ~= 21
    if para(20) == 0.0
        para(20) = input('Initial time = 0, enter correct value in ns: ');
    end
else
    para(20) = 0.0;
end
return
end